import { createSlice, type PayloadAction } from "@reduxjs/toolkit";



const questionare = createSlice({
    name: 'questionare',
    initialState: {
        questions: [],
        answersId: [] as number[],
        standAnswer: [] as number[]
    },
    reducers: {
        setQuestionare: (state, action) => {
            // console.log(action.payload);
            state.questions = action.payload;
        },
        setAnswersId: (state, action: PayloadAction<number>) => {
            // console.log(action.payload);
            state.answersId.push(action.payload);
        },
        setStandAnswer: (state, action: any) => {
            console.log(action.payload);
            action.payload.map((item: any) => {
                item.topic_answer.map((i: any) => {
                    if (i.is_standard_answer) {
                        state.standAnswer.push(i.topic_answer_id)
                    }
                })

            })
        }

    }
})
export default questionare.reducer;
export const { setQuestionare, setAnswersId, setStandAnswer } = questionare.actions;